package DailyPractice.Day25;

import java.util.Scanner;

/**
 * 根数
 * @author lumin
 * @date 2022/05/23 12:53
 **/
public class Num2 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String m = sc.next();
            System.out.println(genshu(m));
        }
    }
    public static int genshu(String m){
        int sum = 0;
        int index = m.length() - 1;
        while(index >= 0){
            sum += m.charAt(index) - '0';
            index--;
        }
        if(sum > 9){
            return genshu(sum);
        }else{
            return sum;
        }
    }
    public static int genshu(int m){
        int sum = 0;
        while(m != 0){
            sum += m % 10;
            m = m / 10;
        }
        if(sum > 9){
            return genshu(sum);
        }else{
            return sum;
        }
    }
}